package reflect;


import sun.plugin2.message.JavaScriptCallMessage;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Scanner;

public class RefiectDemo4 {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
        Person p=new Person();
        p.sayhi();
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入类名");
        String classname=scanner.nextLine();
        System.out.println("请输入方法名");
        String methodname=scanner.nextLine();

        Class cls=Class.forName(classname);
        Object obj=cls.newInstance();

        Method method=cls.getMethod(methodname);

        method.invoke(obj);
        Method method1=cls.getDeclaredMethod("heiehi");
        method.setAccessible(true);
        method.invoke(obj);
        method.setAccessible(false);
    }
}
